package org.michaelrenaud.pathfinder.client.core.app.character;

import org.michaelrenaud.pathfinder.client.core.app.AppPresenter;
import org.michaelrenaud.pathfinder.client.event.CharacterChangeEvent;
import org.michaelrenaud.pathfinder.client.event.CharacterChangeEvent.CharacterChangeHandler;
import org.michaelrenaud.pathfinder.client.place.NameTokens;
import org.michaelrenaud.pathfinder.shared.model.Character;
import org.michaelrenaud.pathfinder.shared.model.StatBlock;

import com.google.gwt.event.shared.EventBus;
import com.google.inject.Inject;
import com.gwtplatform.mvp.client.Presenter;
import com.gwtplatform.mvp.client.View;
import com.gwtplatform.mvp.client.annotations.NameToken;
import com.gwtplatform.mvp.client.annotations.ProxyCodeSplit;
import com.gwtplatform.mvp.client.annotations.ProxyEvent;
import com.gwtplatform.mvp.client.proxy.ProxyPlace;
import com.gwtplatform.mvp.client.proxy.RevealContentEvent;

public class CharacterPresenter extends Presenter<CharacterPresenter.MyView, CharacterPresenter.MyProxy> implements CharacterChangeHandler {

	public interface MyView extends View {
		void setCharacter(Character character, StatBlock statBlock);
	}

	@ProxyCodeSplit @NameToken(NameTokens.character)
	public interface MyProxy extends ProxyPlace<CharacterPresenter> {}

	@Inject
	public CharacterPresenter(
			final EventBus eventBus, 
			final MyView view, 
			final MyProxy proxy) {
		super(eventBus, view, proxy);
	}

	@Override
	protected void revealInParent() {
		RevealContentEvent.fire(this, AppPresenter.TYPE_RevealContent, this);
	}

	@Override
	protected void onBind() {
		super.onBind();
	}

	@ProxyEvent @Override
	public void onCharacterChange(CharacterChangeEvent event) {
		getView().setCharacter(event.getCharacter(), event.getStatBlock());
	}
}
